// 绘制图片
const image = new Image();
image.src = 'https://picsum.photos/200';


const canvas = document.getElementById('canvas');
let ctx, myCtx

if (!canvas) {
  throw new Error('Canvas element not found');
}else{
  ctx = canvas.getContext('2d');
}

const myCanvas = document.getElementById('myCanvas');
if (!myCanvas) {
  throw new Error('Canvas element not found');
}else{
  myCtx = myCanvas.getContext('2d');
  // 设置canvas画布的大小 亦可直接在canvas元素中设置宽高属性
  myCanvas.width = 400;
  myCanvas.height = 400;
  image.onload = () => {
    ctx.drawImage(image, 0, 0);
    myCtx.drawImage(image, 0, 0);
  };
}